/**
 * Created by moc on 2016/3/30.
 */
var crypto = require('crypto');

var token = "sdgfdsg234234sdfsdvw25rwsdg8989g"

var encode = function (obj) {

    var str = JSON.stringify(obj)
    var cipher = crypto.createCipher("aes192", token);
    var enc = cipher.update(str, 'utf8', 'hex');
    enc += cipher.final("hex");
    return enc

}
var decode = function (str) {
    var cipher = crypto.createDecipher("aes192", token);
    var enc = cipher.update(str, 'hex', 'utf8');
    enc += cipher.final('utf8');
    return JSON.parse(enc)
}

var a = encode({a: 1, bv: 111})
var b = decode(a)
console.log(a, b)

exports.encode = encode
exports.decode = decode